// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "ProceduralTerrain.h"
#include "TerrainManager.generated.h"

/**
 * 地形管理器类
 * 负责协调地形生成、管理和更新
 */
UCLASS()
class EMPTYLAND_API ATerrainManager : public AActor
{
    GENERATED_BODY()

public:
    // 构造函数
    ATerrainManager();

protected:
    // 初始化函数
    virtual void BeginPlay() override;

public:
    // 更新函数
    virtual void Tick(float DeltaTime) override;

    /**
     * 生成新地形
     * @param Seed 随机种子
     */
    UFUNCTION(BlueprintCallable, Category = "Terrain Management")
    void GenerateNewTerrain(int32 Seed = 0);

    /**
     * 获取指定位置的地形高度
     * @param WorldLocation 世界位置
     * @return 地形高度
     */
    UFUNCTION(BlueprintCallable, Category = "Terrain Management")
    float GetHeightAtLocation(const FVector& WorldLocation);

    /**
     * 设置地形生成参数
     * @param NewNoiseScale 噪声缩放
     * @param NewOctaves 噪声八度
     * @param NewPersistence 噪声持久性
     * @param NewLacunarity 噪声间隙度
     */
    UFUNCTION(BlueprintCallable, Category = "Terrain Management")
    void SetTerrainParameters(float NewNoiseScale, int32 NewOctaves, float NewPersistence, float NewLacunarity);

private:
    // 程序化地形组件
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Terrain", meta = (AllowPrivateAccess = "true"))
    UProceduralTerrain* ProceduralTerrainComponent;

    // 当前地形种子
    UPROPERTY(EditDefaultsOnly, Category = "Terrain Settings", meta = (AllowPrivateAccess = "true"))
    int32 CurrentTerrainSeed;

    // 地形大小
    UPROPERTY(EditDefaultsOnly, Category = "Terrain Settings", meta = (AllowPrivateAccess = "true"))
    float TerrainSize;

    /**
     * 初始化地形组件
     */
    void InitializeTerrainComponent();

    /**
     * 应用地形设置到游戏世界
     */
    void ApplyTerrainToWorld();
};